package o;

import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Build.VERSION;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow.OnDismissListener;
import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.annotation.StyleRes;
import androidx.appcompat.view.menu.CascadingMenuPopup;
import androidx.core.view.ViewCompat;
import o.ah.e;

@RestrictTo({d.LIBRARY_GROUP})
public class br {
    private bn.d ʻ;
    private boolean ʼ;
    private bm ʽ;
    private final bd ˊ;
    private OnDismissListener ˊॱ;
    private final boolean ˋ;
    private final int ˎ;
    private final Context ˏ;
    private final OnDismissListener ˏॱ;
    private final int ॱ;
    private View ॱॱ;
    private int ᐝ;

    public br(@NonNull Context context, @NonNull bd bdVar, @NonNull View view, boolean z, @AttrRes int i) {
        this(context, bdVar, view, z, i, 0);
    }

    public br(@NonNull Context context, @NonNull bd bdVar, @NonNull View view, boolean z, @AttrRes int i, @StyleRes int i2) {
        this.ᐝ = 8388611;
        this.ˏॱ = new OnDismissListener(this) {
            final /* synthetic */ br ˊ;

            {
                this.ˊ = r1;
            }

            public void onDismiss() {
                this.ˊ.ˊ();
            }
        };
        this.ˏ = context;
        this.ˊ = bdVar;
        this.ॱॱ = view;
        this.ˋ = z;
        this.ˎ = i;
        this.ॱ = i2;
    }

    public void ˊ(@Nullable OnDismissListener onDismissListener) {
        this.ˊॱ = onDismissListener;
    }

    public void ˋ(@NonNull View view) {
        this.ॱॱ = view;
    }

    public void ˏ(boolean z) {
        this.ʼ = z;
        if (this.ʽ != null) {
            this.ʽ.ˎ(z);
        }
    }

    public void ˎ(int i) {
        this.ᐝ = i;
    }

    public void ˋ() {
        if (!ˏ()) {
            throw new IllegalStateException("MenuPopupHelper cannot be used without an anchor");
        }
    }

    @NonNull
    public bm ॱ() {
        if (this.ʽ == null) {
            this.ʽ = ʻ();
        }
        return this.ʽ;
    }

    public boolean ˏ() {
        if (ᐝ()) {
            return true;
        }
        if (this.ॱॱ == null) {
            return false;
        }
        ॱ(0, 0, false, false);
        return true;
    }

    public boolean ˋ(int i, int i2) {
        if (ᐝ()) {
            return true;
        }
        if (this.ॱॱ == null) {
            return false;
        }
        ॱ(i, i2, true, true);
        return true;
    }

    @NonNull
    private bm ʻ() {
        bm cascadingMenuPopup;
        Display defaultDisplay = ((WindowManager) this.ˏ.getSystemService("window")).getDefaultDisplay();
        Point point = new Point();
        if (VERSION.SDK_INT >= 17) {
            defaultDisplay.getRealSize(point);
        } else {
            defaultDisplay.getSize(point);
        }
        if ((Math.min(point.x, point.y) >= this.ˏ.getResources().getDimensionPixelSize(e.ॱ) ? 1 : null) != null) {
            cascadingMenuPopup = new CascadingMenuPopup(this.ˏ, this.ॱॱ, this.ˎ, this.ॱ, this.ˋ);
        } else {
            cascadingMenuPopup = new bw(this.ˏ, this.ˊ, this.ॱॱ, this.ˎ, this.ॱ, this.ˋ);
        }
        cascadingMenuPopup.ˊ(this.ˊ);
        cascadingMenuPopup.ॱ(this.ˏॱ);
        cascadingMenuPopup.ˎ(this.ॱॱ);
        cascadingMenuPopup.ˎ(this.ʻ);
        cascadingMenuPopup.ˎ(this.ʼ);
        cascadingMenuPopup.ॱ(this.ᐝ);
        return cascadingMenuPopup;
    }

    private void ॱ(int i, int i2, boolean z, boolean z2) {
        bm ॱ = ॱ();
        ॱ.ॱ(z2);
        if (z) {
            if ((hj.ˎ(this.ᐝ, ViewCompat.ʼ(this.ॱॱ)) & 7) == 5) {
                i -= this.ॱॱ.getWidth();
            }
            ॱ.ˏ(i);
            ॱ.ˎ(i2);
            int i3 = (int) ((this.ˏ.getResources().getDisplayMetrics().density * 48.0f) / 2.0f);
            ॱ.ˋ(new Rect(i - i3, i2 - i3, i + i3, i3 + i2));
        }
        ॱ.ˊ();
    }

    public void ˎ() {
        if (ᐝ()) {
            this.ʽ.ˋ();
        }
    }

    protected void ˊ() {
        this.ʽ = null;
        if (this.ˊॱ != null) {
            this.ˊॱ.onDismiss();
        }
    }

    public boolean ᐝ() {
        return this.ʽ != null && this.ʽ.ˎ();
    }

    public void ˋ(@Nullable bn.d dVar) {
        this.ʻ = dVar;
        if (this.ʽ != null) {
            this.ʽ.ˎ(dVar);
        }
    }
}
